<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */
namespace Plugin\Device\Http\Request\Admin;

use Hyperf\Validation\Request\FormRequest;

/**
 * 广播设备验证数据类
 */
class RdDeviceBroadcastRequest extends FormRequest
{
    /**
     * 场景配置
     */
    protected array $scenes = [
        'index' => [
            'id',
            'code',
            'name',
            'server_id',
            'ip',
            'device_id',
            'rod_id',
            'status',
            'volume',
            'remarks',
            'addr',
            'created_at',
            'updated_at',
        ],
        'create' => [
            'code',
            'name',
            'server_id',
            'ip',
            'device_id',
            'rod_id',
            'status',
            'volume',
            'remarks',
            'addr',
            'stand_id',
        ],
        'update' => [
            'code',
            'name',
            'server_id',
            'ip',
            'device_id',
            'rod_id',
            'status',
            'volume',
            'remarks',
            'addr',
            'stand_id',
        ]
    ];

    public function authorize(): bool
    {
        return true;
    }


    /**
     * 新增数据验证规则
     * return array
     */
    public function rules(): array
    {
        return [
            'id' => 'integer',
            //设备编码 验证
            'code' => 'max:255',
            //设备名称 验证
            'name' => 'max:255',
            //服务器id 验证
            'server_id' => 'integer',
            //设备ip 验证
            'ip' => 'ip',
            //设备编号 验证
            'device_id' => 'integer',
            //装置ID 验证
            'rod_id' => 'integer',
            //设备状态 验证
            'status' => 'integer|between:0,255',
            //音量 验证
            'volume' => 'integer|between:0,100',
            //备注 验证
            'remarks' => 'max:255',
            //位置 验证
            'addr' => 'max:255',
            //站点id 验证
            'stand_id' => 'integer',

        ];
    }


    /**
     * 字段映射名称
     * return array
     */
    public function attributes(): array
    {
        return [
            'id' => 'ID',
            'code' => '设备编码',
            'name' => '设备名称',
            'server_id' => '服务器ID',
            'ip' => '设备IP',
            'device_id' => '设备编号',
            'rod_id' => '装置ID',
            'status' => '设备状态',
            'volume' => '音量',
            'remarks' => '备注',
            'addr' => '位置',
            'created_by' => '创建者',
            'updated_by' => '更新者',
            'stand_id' => '站点ID',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',

        ];
    }

public function messages(): array
{
    return [
            'id.integer' => 'ID必须是整数',
            'code.required' => '必填设备编码',
            'code.max' => '设备编码长度不能超过255个字符',
            'name.required' => '必填设备名称',
            'name.max' => '设备名称长度不能超过255个字符',
            'server_id.integer' => '服务器ID必须是整数',
            'ip.ip' => '设备IP格式不正确',
            'device_id.integer' => '设备编号必须是整数',
            'rod_id.required' => '必填装置ID',
            'rod_id.integer' => '装置ID必须是整数',
            'status.integer' => '设备状态必须是整数',
            'status.between' => '设备状态必须在0-255之间',
            'volume.integer' => '音量必须是整数',
            'volume.between' => '音量必须在0-100之间',
            'remarks.max' => '备注长度不能超过255个字符',
            'addr.max' => '位置长度不能超过255个字符',
            'stand_id.integer' => '站点ID必须是整数',
            'created_by.required' => '必填创建者',
            'updated_by.required' => '必填更新者',

    ];
}
}